knitr::opts_chunk$set(echo = TRUE)
source("3_b_Compute_Tweetscores.R")
setwd("C:/Users/cowbu/Dropbox/ajps_us")
source("3_b_Compute_Tweetscores.R")
setwd("C:/Users/cowbu/Dropbox/ajps_us/scripts_new")
source("3_b_Compute_Tweetscores.R")
knitr::opts_chunk$set(echo = TRUE)
knitr::include_graphics('figures/figure2.pdf')
source("7a_Robustness_Individual.R")
load("data_clean/compare_measures_rc.rdata")
load("data_clean/main_analysis.rdata")
library(modelsummary)
getwd()
load("data/main_analysis.rdata")
source("tools/toolbox.R")
me$theta<-log(me$theta)*20
me$theta_se<-me$theta_se*20
me$theta_r<-log(me$theta_r)*20
me$theta_r_se<-me$theta_r_se*20
me$winner<-factor(me$winner,labels=c("Loser","Winner"))
names(me)
me<-me[me$ttp>=-25,]
me<-me[me$ttp<=25,]
pdf("./figures/figure3.pdf",width = 12,height = 8)
plot_ts(me_ts = me,var = "theta",time = "ttp",var2 = "theta_se",ci=2)
dev.off()
me$party<-as.factor(me$party)
me$dep<-me$theta
me$dep2<-me$theta_r
me$interven<-me$ttp>0
me$loser<-relevel(me$winner,ref = "Winner")
me$share<-me$poltweets/me$n
# Democrats
checkm1_d<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="D",])
summary(checkm1_d)
checkm1_pd<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+poltweets,data=me[me$party=="D",])
summary(checkm1_pd)
checkm1_ds<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+share,data=me[me$party=="D",])
summary(checkm1_ds)
checkm2_d<-lm(dep2~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="D",])
summary(checkm2_d)
### Loser only models, dem
checkm1_d_l<-lm(dep~ttp+interven+ttp*interven*ttp,data=me[me$party=="D" & me$loser=="Loser",])
summary(checkm1_d_l)
checkm2_d_l<-lm(dep2~ttp+interven+ttp*interven*ttp,data=me[me$party=="D" & me$loser=="Loser",])
summary(checkm2_d_l)
# Republicans
checkm1_r<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="R",])
summary(checkm1_r)
checkm1_rp<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+poltweets,data=me[me$party=="R",])
summary(checkm1_rp)
checkm1_rs<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+share,data=me[me$party=="R",])
summary(checkm1_rs)
checkm2_r<-lm(dep2~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="R",])
summary(checkm2_d)
nrow(me)
### Loser only models, rep
checkm1_r_l<-lm(dep~ttp+interven+ttp*interven*ttp,data=me[me$party=="R" & me$loser=="Loser",])
summary(checkm1_r_l)
checkm2_r_l<-lm(dep2~ttp+interven+ttp*interven*ttp,data=me[me$party=="R" & me$loser=="Loser",])
summary(checkm2_r_l)
model1<-checkm1_d
model2<-checkm1_r
interval1 <- -qnorm((1-0.9)/2)  # 90% multiplier
interval2 <- -qnorm((1-0.95)/2)  # 95% multiplier
######## Controlling for number of political tweets
model1Frame <- data.frame(Variable = rownames(summary(model1)$coef),
Coefficient = summary(model1)$coef[, 1],
SE = summary(model1)$coef[, 2],
Model = "Democrats")
model1Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
model2Frame <- data.frame(Variable = rownames(summary(model2)$coef),
Coefficient = summary(model2)$coef[, 1],
SE = summary(model2)$coef[, 2],
Model = "Republicans")
# Combine these data.frames
# Combine these data.frames
model2Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
level_order1<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.
colscheme<-c("blue","red")
zp1<-mult_plot(allModelFrame,level_order=level_order1,sz=14,l=1.5,legend=T)
## Coefficient plot not part of the paper
#pdf('./appendix/figures/figure_x.pdf',width = 12, height = 10)
#zp1
#dev.off()
#level_order2<-c("Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm1_d,checkm1_r)
level_order<-c("Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm1_d,checkm1_r,type="latex",out ="./tables/table0.tex",covariate.labels = level_order,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
vars<-c("Time","Post-Primary","Loser","Post-Primary : Time","Post-Primary : Loser","Loser : Time","Post-Primary : Loser : Time" , "Intercept")
stargazer(checkm1_d,checkm1_r,checkm1_d_l,checkm1_r_l,type="latex",out ="./tables/table1.tex",covariate.labels = vars,label = "itsparty",title = "ITS Results: Party Level",column.labels = c("Democrats","Republicans","Democrats","Republicans"),dep.var.labels=c("All Candidates","Losers Only"),style = "apsr")
#### Plot models with correction, controlling for Policy Tweets (Table 9, Appendix)
model1<-checkm1_pd
model2<-checkm1_rp
# Put model estimates into temporary data.frames:
model1Frame <- data.frame(Variable = rownames(summary(model1)$coef),
Coefficient = summary(model1)$coef[, 1],
SE = summary(model1)$coef[, 2],
Model = "Democrats")
model1Frame$Variable<-c('Intercept',"Time to Primary","After Primary","Total Policy Tweets","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
model2Frame <- data.frame(Variable = rownames(summary(model2)$coef),
Coefficient = summary(model2)$coef[, 1],
SE = summary(model2)$coef[, 2],
Model = "Republicans")
# Combine these data.frames
# Combine these data.frames
model2Frame$Variable<-c('Intercept',"Time to Primary","After Primary","Total Policy Tweets","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
level_order1<-c('Intercept',"Time to Primary","After Primary","Total Policy Tweets","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.
colscheme<-c("blue","red")
zp1<-mult_plot(allModelFrame,level_order=level_order1,sz=14,l=1.5,legend=T)
#pdf('./appendix/figures/figure13.pdf',width = 12, height = 10)
#zp1
#dev.off()
level_order2<-c("Time to Primary","After Primary","loser","Total Policy Tweets","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm1_pd,checkm1_rp,type="latex",out ="./appendix/tables/table9.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
#stargazer(checkm1,checkm2,type="latex",out ="./tables/party_models.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
### Exporting Results only using Policy Tweets:
model1<-checkm2_d
model2<-checkm2_r
# Put model estimates into temporary data.frames:
model1Frame <- data.frame(Variable = rownames(summary(model1)$coef),
Coefficient = summary(model1)$coef[, 1],
SE = summary(model1)$coef[, 2],
Model = "Democrats")
model1Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
model2Frame <- data.frame(Variable = rownames(summary(model2)$coef),
Coefficient = summary(model2)$coef[, 1],
SE = summary(model2)$coef[, 2],
Model = "Republicans")
# Combine these data.frames
# Combine these data.frames
model2Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
level_order1<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.
colscheme<-c("blue","red")
zp1<-mult_plot(allModelFrame,level_order=level_order1,sz=14,l=1.5,legend=T)
pdf('./appendix/figures/figure13.pdf',width = 12, height = 10)
zp1
dev.off()
level_order2<-c("Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm2_d,checkm2_r,covariate.labels = level_order2)
stargazer(checkm2_d,checkm2_r,type="latex",out ="./appendix/tables/table2.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
#stargazer(checkm1,checkm2,type="latex",out ="./tables/party_models.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
stargazer(checkm2_d,checkm2_r,checkm2_d_l,checkm2_r_l,type="latex",out ="./tables/table1.tex",covariate.labels = level_order,dep.var.labels = "Position",label = "itsparty",title = "ITS Results: Policy Tweets Only",column.labels = c("Democrats","Republicans"),style = "apsr")
### lagged dv, fixed effects
rl<-me[me$party=="R" & me$loser=="Loser",]
dl<-me[me$party=="D" & me$loser=="Winner",]
dw<-me[me$party=="D" & me$loser=="Loser",]
rw<-me[me$party=="R" & me$loser=="Winner",]
rw<-rw[order(rw$ttp,decreasing = F),]
dw<-dw[order(dw$ttp,decreasing = F),]
rl<-rl[order(rl$ttp,decreasing = F),]
dl<-dl[order(dl$ttp,decreasing = F),]
rw$dep_lag<-lag(rw$dep,1)
rl$dep_lag<-lag(rl$dep,1)
dw$dep_lag<-lag(dw$dep,1)
dl$dep_lag<-lag(dl$dep,1)
d2<-rbind(dw,dl)
r2<-rbind(rw,rl)
checkm1_r_lag<-lm(dep~dep_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=r2)
summary(checkm1_r_lag)
checkm1_d_lag<-lm(dep~dep_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=d2)
summary(checkm1_d_lag)
rw$dep2_lag<-lag(rw$dep2,1)
rl$dep2_lag<-lag(rl$dep2,1)
dw$dep2_lag<-lag(dw$dep2,1)
dl$dep2_lag<-lag(dl$dep2,1)
d2<-rbind(dw,dl)
r2<-rbind(rw,rl)
checkm2_r_lag<-lm(dep2~dep2_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=r2)
summary(checkm2_r_lag)
checkm2_d_lag<-lm(dep2~dep2_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=d2)
summary(checkm2_d_lag)
stargazer(checkm1_d_lag,checkm1_r_lag,checkm2_d_lag,checkm2_r_lag,type="latex",out ="./tables/table15.tex",dep.var.labels = "Position",label = "itsparty",title = "Lagged DC As Additional Control",column.labels = c("Democrats","Republicans","Democrats","Republicans"),style = "apsr")
checkm2_d_ff<-lm(dep~loser*interven,data=d2)
summary(checkm2_d_ff)
checkm2_r_ff<-lm(dep~loser*interven,data=r2)
summary(checkm2_r_ff)
stargazer(checkm2_d_ff,checkm2_r_ff,type="latex",out ="./tables/table14.tex",dep.var.labels = "Position",label = "itsparty",title = "Two-Way-Fixed-Effect Version",column.labels = c("Democrats","Republicans"),style = "apsr")
load("data/main_analysis.rdata")
setwd("..")
load("data/main_analysis.rdata")
source("tools/toolbox.R")
me$theta<-log(me$theta)*20
me$theta_se<-me$theta_se*20
me$theta_r<-log(me$theta_r)*20
me$theta_r_se<-me$theta_r_se*20
me$winner<-factor(me$winner,labels=c("Loser","Winner"))
names(me)
me<-me[me$ttp>=-25,]
me<-me[me$ttp<=25,]
pdf("./figures/figure3.pdf",width = 12,height = 8)
plot_ts(me_ts = me,var = "theta",time = "ttp",var2 = "theta_se",ci=2)
dev.off()
me$party<-as.factor(me$party)
me$dep<-me$theta
me$dep2<-me$theta_r
me$interven<-me$ttp>0
me$loser<-relevel(me$winner,ref = "Winner")
me$share<-me$poltweets/me$n
# Democrats
checkm1_d<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="D",])
summary(checkm1_d)
checkm1_pd<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+poltweets,data=me[me$party=="D",])
summary(checkm1_pd)
checkm1_ds<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+share,data=me[me$party=="D",])
summary(checkm1_ds)
checkm2_d<-lm(dep2~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="D",])
summary(checkm2_d)
### Loser only models, dem
checkm1_d_l<-lm(dep~ttp+interven+ttp*interven*ttp,data=me[me$party=="D" & me$loser=="Loser",])
summary(checkm1_d_l)
checkm2_d_l<-lm(dep2~ttp+interven+ttp*interven*ttp,data=me[me$party=="D" & me$loser=="Loser",])
summary(checkm2_d_l)
# Republicans
checkm1_r<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="R",])
summary(checkm1_r)
checkm1_rp<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+poltweets,data=me[me$party=="R",])
summary(checkm1_rp)
checkm1_rs<-lm(dep~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven+share,data=me[me$party=="R",])
summary(checkm1_rs)
checkm2_r<-lm(dep2~ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=me[me$party=="R",])
summary(checkm2_d)
nrow(me)
### Loser only models, rep
checkm1_r_l<-lm(dep~ttp+interven+ttp*interven*ttp,data=me[me$party=="R" & me$loser=="Loser",])
summary(checkm1_r_l)
checkm2_r_l<-lm(dep2~ttp+interven+ttp*interven*ttp,data=me[me$party=="R" & me$loser=="Loser",])
summary(checkm2_r_l)
model1<-checkm1_d
model2<-checkm1_r
interval1 <- -qnorm((1-0.9)/2)  # 90% multiplier
interval2 <- -qnorm((1-0.95)/2)  # 95% multiplier
######## Controlling for number of political tweets
model1Frame <- data.frame(Variable = rownames(summary(model1)$coef),
Coefficient = summary(model1)$coef[, 1],
SE = summary(model1)$coef[, 2],
Model = "Democrats")
model1Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
model2Frame <- data.frame(Variable = rownames(summary(model2)$coef),
Coefficient = summary(model2)$coef[, 1],
SE = summary(model2)$coef[, 2],
Model = "Republicans")
# Combine these data.frames
# Combine these data.frames
model2Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
level_order1<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.
colscheme<-c("blue","red")
zp1<-mult_plot(allModelFrame,level_order=level_order1,sz=14,l=1.5,legend=T)
## Coefficient plot not part of the paper
#pdf('./appendix/figures/figure_x.pdf',width = 12, height = 10)
#zp1
#dev.off()
#level_order2<-c("Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm1_d,checkm1_r)
level_order<-c("Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm1_d,checkm1_r,type="latex",out ="./tables/table0.tex",covariate.labels = level_order,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
vars<-c("Time","Post-Primary","Loser","Post-Primary : Time","Post-Primary : Loser","Loser : Time","Post-Primary : Loser : Time" , "Intercept")
stargazer(checkm1_d,checkm1_r,checkm1_d_l,checkm1_r_l,type="latex",out ="./tables/table1.tex",covariate.labels = vars,label = "itsparty",title = "ITS Results: Party Level",column.labels = c("Democrats","Republicans","Democrats","Republicans"),dep.var.labels=c("All Candidates","Losers Only"),style = "apsr")
#### Plot models with correction, controlling for Policy Tweets (Table 9, Appendix)
model1<-checkm1_pd
model2<-checkm1_rp
# Put model estimates into temporary data.frames:
model1Frame <- data.frame(Variable = rownames(summary(model1)$coef),
Coefficient = summary(model1)$coef[, 1],
SE = summary(model1)$coef[, 2],
Model = "Democrats")
model1Frame$Variable<-c('Intercept',"Time to Primary","After Primary","Total Policy Tweets","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
model2Frame <- data.frame(Variable = rownames(summary(model2)$coef),
Coefficient = summary(model2)$coef[, 1],
SE = summary(model2)$coef[, 2],
Model = "Republicans")
# Combine these data.frames
# Combine these data.frames
model2Frame$Variable<-c('Intercept',"Time to Primary","After Primary","Total Policy Tweets","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
level_order1<-c('Intercept',"Time to Primary","After Primary","Total Policy Tweets","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.
colscheme<-c("blue","red")
zp1<-mult_plot(allModelFrame,level_order=level_order1,sz=14,l=1.5,legend=T)
#pdf('./appendix/figures/figure13.pdf',width = 12, height = 10)
#zp1
#dev.off()
level_order2<-c("Time to Primary","After Primary","loser","Total Policy Tweets","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm1_pd,checkm1_rp,type="latex",out ="./appendix/tables/table9.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
#stargazer(checkm1,checkm2,type="latex",out ="./tables/party_models.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
### Exporting Results only using Policy Tweets:
model1<-checkm2_d
model2<-checkm2_r
# Put model estimates into temporary data.frames:
model1Frame <- data.frame(Variable = rownames(summary(model1)$coef),
Coefficient = summary(model1)$coef[, 1],
SE = summary(model1)$coef[, 2],
Model = "Democrats")
model1Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
model2Frame <- data.frame(Variable = rownames(summary(model2)$coef),
Coefficient = summary(model2)$coef[, 1],
SE = summary(model2)$coef[, 2],
Model = "Republicans")
# Combine these data.frames
# Combine these data.frames
model2Frame$Variable<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
level_order1<-c('Intercept',"Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser")
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.
colscheme<-c("blue","red")
zp1<-mult_plot(allModelFrame,level_order=level_order1,sz=14,l=1.5,legend=T)
pdf('./appendix/figures/figure13.pdf',width = 12, height = 10)
zp1
dev.off()
level_order2<-c("Time to Primary","After Primary","loser","TTP:After Primary","After Primary:loser","TTP:loser","ttp:After Primary:loser",'Intercept')
stargazer(checkm2_d,checkm2_r,covariate.labels = level_order2)
stargazer(checkm2_d,checkm2_r,type="latex",out ="./appendix/tables/table2.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
#stargazer(checkm1,checkm2,type="latex",out ="./tables/party_models.tex",covariate.labels = level_order2,dep.var.labels = "Position",label = "itsparty",title = "Interrupted Time-Series Analysis Results",column.labels = c("Democrats","Republicans"),style = "apsr")
stargazer(checkm2_d,checkm2_r,checkm2_d_l,checkm2_r_l,type="latex",out ="./tables/table1.tex",covariate.labels = level_order,dep.var.labels = "Position",label = "itsparty",title = "ITS Results: Policy Tweets Only",column.labels = c("Democrats","Republicans"),style = "apsr")
### lagged dv, fixed effects
rl<-me[me$party=="R" & me$loser=="Loser",]
dl<-me[me$party=="D" & me$loser=="Winner",]
dw<-me[me$party=="D" & me$loser=="Loser",]
rw<-me[me$party=="R" & me$loser=="Winner",]
rw<-rw[order(rw$ttp,decreasing = F),]
dw<-dw[order(dw$ttp,decreasing = F),]
rl<-rl[order(rl$ttp,decreasing = F),]
dl<-dl[order(dl$ttp,decreasing = F),]
rw$dep_lag<-lag(rw$dep,1)
rl$dep_lag<-lag(rl$dep,1)
dw$dep_lag<-lag(dw$dep,1)
dl$dep_lag<-lag(dl$dep,1)
d2<-rbind(dw,dl)
r2<-rbind(rw,rl)
checkm1_r_lag<-lm(dep~dep_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=r2)
summary(checkm1_r_lag)
checkm1_d_lag<-lm(dep~dep_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=d2)
summary(checkm1_d_lag)
rw$dep2_lag<-lag(rw$dep2,1)
rl$dep2_lag<-lag(rl$dep2,1)
dw$dep2_lag<-lag(dw$dep2,1)
dl$dep2_lag<-lag(dl$dep2,1)
d2<-rbind(dw,dl)
r2<-rbind(rw,rl)
checkm2_r_lag<-lm(dep2~dep2_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=r2)
summary(checkm2_r_lag)
checkm2_d_lag<-lm(dep2~dep2_lag+ttp+interven+ttp*interven+loser+loser*interven+loser*ttp+loser*ttp*interven,data=d2)
summary(checkm2_d_lag)
stargazer(checkm1_d_lag,checkm1_r_lag,checkm2_d_lag,checkm2_r_lag,type="latex",out ="./tables/table15.tex",dep.var.labels = "Position",label = "itsparty",title = "Lagged DC As Additional Control",column.labels = c("Democrats","Republicans","Democrats","Republicans"),style = "apsr")
checkm2_d_ff<-lm(dep~loser*interven,data=d2)
summary(checkm2_d_ff)
checkm2_r_ff<-lm(dep~loser*interven,data=r2)
summary(checkm2_r_ff)
stargazer(checkm2_d_ff,checkm2_r_ff,type="latex",out ="./tables/table14.tex",dep.var.labels = "Position",label = "itsparty",title = "Two-Way-Fixed-Effect Version",column.labels = c("Democrats","Republicans"),style = "apsr")
modelsummary::modelsummary(list(checkm2_d_ff))
modelsummary::modelsummary(list(checkm2_d_ff),output = "latex")
## Build Corpora. Depending your OS, you might have trouble with file encoding. Please ignore warnings.
gc()
suppressMessages(source("scripts_new/1_Preprocessing.R"))
rm(list = ls())
gc()
source("scripts_new/3_b_Validation_Individual.R")
rm(list = ls())
gc()
source("scripts_new/3_b_Validation_Individual.R")
ex1<-read.csv("data/expert_scores.csv",header = F)
names(ex1)<-c("name","party_code","state","type","xscore")
ex1<-ex1[ex1$type=="Senator",]
nom<-strsplit(ex1$name," ")
ex1$lastname<-tolower(sapply(nom,"[[",2))
View(ex1)
names(ex1)<-c("name","party_code","state","type","xscore")
ex1<-ex1[ex1$type=="Senator",]
nom<-strsplit(ex1$name," ")
ex1<-read.csv("data/expert_scores.csv",header = F, fileEncoding = 'UTF-8')
names(ex1)<-c("name","party_code","state","type","xscore")
ex1<-ex1[ex1$type=="Senator",]
nom<-strsplit(ex1$name," ")
ex1$lastname<-tolower(sapply(nom,"[[",2))
rm(list = ls())
gc()
source("scripts_new/3_b_Validation_Individual.R")
rm(list = ls())
gc()
source("scripts_new/3_b_Validation_Individual.R")
ex1<-read.csv("data/expert_scores.csv",header = F, fileEncoding = 'latin1')
names(ex1)<-c("name","party_code","state","type","xscore")
ex1<-ex1[ex1$type=="Senator",]
nom<-strsplit(ex1$name," ")
ex1$lastname<-tolower(sapply(nom,"[[",2))
nom<-strsplit(ex1$name," ")
ex1$lastname<-tolower(sapply(nom,"[[",2))
m7<-m6[m6$chamber=="Senate",]
rm(list = ls())
gc()
source("scripts_new/3_b_Validation_Individual.R")
savehistory("~/Other/Journal Submissions/Mannheim Project/Replication_fin/Replication_fin/.Rhistory")
